﻿Date.prototype.add = function(datepart, number, returnNewObjec) {
    ///<summary> 
    ///日期加减。 
    ///若returnNewObjec参数为true值，则操作结果由一个新的日期对象返回，原日期对象不变， 
    ///否则返回的是原日期对象,此时原日期对象的值是操作结果. 
    ///</summary> 
    ///<param name="datepart" type="string"> 
    ///日期加减的部分: 
    ///Year, yy, yyyy--年 
    ///quarter, qq, q --季 
    ///Month, mm, m -- 月 
    ///dayofyear, dy, y-- 日 
    ///Day, dd, d -- 日 
    ///Week, wk, ww -- 周 
    ///Hour, hh -- 小时 
    ///minute, mi, n -- 分钟 
    ///second, ss, s -- 秒 
    ///millisecond, ms -- 毫秒 
    ///</param> 
    ///<param name="number" type="int"> 
    ///要加减的数量 
    ///</param> 
    ///<param name="returnNewObjec" type="bool"> 
    ///是否返回新的日期对象。若参数为true值，则返回一个新的日期对象，否则返回的是当前日期对象. 
    ///</param> 
    ///<returns type="Date"> 
    ///返回一个日期对象 
    ///</returns> 
    var regExp = /^\d+$/;
    if (regExp.test(number)) {
        number = parseInt(number);
    }
    else { number = 0; }
    datepart = datepart.toLowerCase();
    var tDate;
    if (typeof (returnNewObjec) == "boolean") {
        if (returnNewObjec == true) {
            tDate = new Date(this);
        }
        else { tDate = this; }
    }
    else { tDate = this; }
    switch (datepart) {
        case "year":
        case "yy":
        case "yyyy":
            tDate.setFullYear(this.getFullYear() + number);
            break;
        case "quarter":
        case "qq":
        case "q":
            tDate.setMonth(this.getMonth() + (number * 3));
            break;
        case "month":
        case "mm":
        case "m":
            tDate.setMonth(this.getMonth() + number);
            break;
        case "dayofyear":
        case "dy":
        case "y":
        case "day":
        case "dd":
        case "d":
            tDate.setDate(this.getDate() + number);
            break;
        case "week":
        case "wk":
        case "ww":
            tDate.setDate(this.getDate() + (number * 7));
            break;
        case "hour":
        case "hh":
            tDate.setHours(this.getHours() + number);
            break
        case "minute":
        case "mi":
        case "n":
            tDate.setMinutes(this.getMinutes() + number);
            break
        case "second":
        case "ss":
        case "s":
            tDate.setSeconds(this.getSeconds() + number);
            break;
        case "millisecond":
        case "ms":
            tDate.setMilliseconds(this.getMilliseconds() + number);
            break;
    }
    return tDate;
}


function ShowTime() {
    var v_str = '2000/01/01' + ' ' + document.getElementById('lbTime').innerText;

    var v_hh = "";
    var v_mi = "";
    var v_ss = "";
    var v_datetime = new Date('2000/01/01' + ' ' + document.getElementById('lbTime').innerText);

    v_datetime.add('ss', 1, false);

    if (v_datetime.getHours() < 10) {
        v_hh = "0" + v_datetime.getHours();
    }
    else {
        v_hh = v_datetime.getHours();
    }

    if (v_datetime.getMinutes() < 10) {
        v_mi = "0" + v_datetime.getMinutes();
    }
    else {
        v_mi = v_datetime.getMinutes();
    }

    if (v_datetime.getSeconds() < 10) {
        v_ss = "0" + v_datetime.getSeconds();
    }
    else {
        v_ss = v_datetime.getSeconds();
    }

    document.getElementById('lbTime').innerText = v_hh + ":" + v_mi + ":" + v_ss;

    //alert(v_datetime);
    LoadTimer();
}

function LoadTimer() {
    setTimeout("ShowTime()", 1000);
}
//加载效果
function loading() {
    //LoadTimer();
    setTimeout(function() {
        Ext.get('loading').remove();
        Ext.get('loading-mask').fadeOut({ remove: true });
    }, 1000);
}
//得到用户ID
//loaduser();
//alert(user);

//--设置一些共有参数
Ext.BLANK_IMAGE_URL = "res/images/framework/s.gif";
Ext.QuickTips.init();


///=================================================头部
var top1 = new Ext.BoxComponent({
    el: "top",
    height: 60
});

//------------------------------------------north设置
var north = new Ext.Panel({
    titleCollapse: false,
    collapsedCls: '',
    border: false,
    collapsible: false,
    //添加动画效果
    layoutConfig: {
        animate: true
    },
    region: "north",
    height: 60,
    items: [top1]
});


//----------------------------------------------左边
var root = new Ext.tree.AsyncTreeNode({
    id: rootsid + '',
    url: '#',
    text: "国家政策粮食竞价销售资金结算管理平台",
    loader: new Ext.tree.TreeLoader({
        url: "Data/DTree.ashx",
        listeners: {
            "beforeload": function(treeloader, node) {
                treeloader.baseParams = {
                    id: node.attributes.id,
                    url: node.attributes.url,
                    method: 'POST'
                };
            }
        }
    })
});

var treenode = new Ext.tree.TreePanel({
    //如果超出范围带自动滚动条
    autoScroll: false,
    root: root,
    //默认根目录不显示
    rootVisible: false,
    border: false,
    animate: true,
    lines: true,
    enableDD: false,
    containerScroll: true,
    listeners:
    {
        "click": function(node, event) {
            //叶子节点点击不进入链接             
            if (node.isLeaf()) {
                // 显示叶子节点菜单
                event.stopEvent();
                var n = center.getComponent(node.id);
                if (!n) { //判断是否已经打开该面板   
                    n = center.add({
                        xtype: "panel",
                        id: node.id,
                        iconCls: node.attributes.iconCls,
                        title: node.attributes.pagetext,
                        closable: true,  //通过html载入目标页
                        //autoLoad: { url: node.attributes.url, callback: this.initSearch, scope: this }
                        html: '<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="'
                                + (node.attributes.url.indexOf('?') > 0 ? node.attributes.url +
                                '&' : node.attributes.url + '?') + 'MenuCode=' + node.id + '&userId=' + (userid != null ? userid : '') + '"></iframe>'
                    });
                }
                else {
                    center.remove(n);
                    n = center.add({
                        xtype: "panel",
                        id: node.id,
                        iconCls: node.attributes.iconCls,
                        title: node.attributes.pagetext,
                        closable: true,  //通过html载入目标页
                        html: '<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src='
                             + (node.attributes.url.indexOf('?') > 0 ? node.attributes.url
                             + '&' : node.attributes.url + '?') + 'MenuCode=' + node.id + '&userId=' + (userid != null ? userid : '') + '></iframe>'
                    });
                }
                center.setActiveTab(n);
            } else {
                //不是叶子节点不触发事件
                event.stopEvent();
                //点击时展开
                node.toggle();
            }
        }
    }

});
//加载时自动展开根节点
//treenode.getRootNode().toggle();
//treenode.expandAll();

//添加左边
var west = new Ext.Panel({
    //自动收缩按钮
    collapsible: true,
    //collapseMode: 'mini',
    split: false,
    useSplitTips: false,
    header: true,
    border: false,
    collapsed: true,
    width: 225,
    layout: "fit",
    extraCls: "roomtypegridbbar",
    //添加动画效果
    layoutConfig: {
        animate: true
    },
    region: "west",
    title: '资金结算系统',
    //
    items: [{
        title: "<b>操作菜单</b>",
        autoScroll: true,
        iconCls: "hotelmanageicon",
        items: [treenode],
        split: false,
        useSplitTips: false
}]
    });

    //-------------------------------------------------中间

    var center = new Ext.TabPanel({
        //距两边间距
        style: "padding:0 0 0 1px",
        border: true,
        region: "center",
        plain: false,
        //默认选中第一个
        activeItem: 0,
        //如果Tab过多会出现滚动条
        enableTabScroll: true,
        //加载时渲染所有
        //deferredRender:false,
        layoutOnTabChange: true,
        items: [{
            xtype: "panel",
            id: "index",
            iconCls: "indexicon",
            title: "首 页",
            //closable:true,
            html: "<iframe src='HomePage.aspx?parentMenuId=0' scrolling='yes' frameborder=0 width=100% height=100%></iframe>"}],
            plugins: new Ext.ux.TabCloseMenu()
        });

        var botton = new Ext.BoxComponent({
            el: "botton",
            height: 30
        });
        //底部
        var south = new Ext.Panel({
            border: false,
            region: "south",
            height: 25,
            items: [botton]
        });


        //////////////////////////////////////////////////////////
        Ext.onReady(function() {
            var vp = new Ext.Viewport({
                layout: "border",
                items: [north, west, center]
            });
        });

